home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / PowerPC / Dev / PPCRelease / Examples / Tasks / Startup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-26  |  4.5 KB  |  159 lines

  1. /* Stefan Burstrom Source and concept
  2.  * Adapted by Ralph Schmidt
  3.  */
  4.  
  5. #include <exec/types.h>
  6. #include <exec/nodes.h>
  7. #include <exec/lists.h>
  8. #include <exec/memory.h>
  9. #include <utility/tagitem.h>
  10. #include <powerup/ppclib/interface.h>
  11. #include <powerup/ppclib/message.h>
  12. #include <powerup/ppclib/tasks.h>
  13. #include <powerup/proto/ppc.h>
  14. #include <proto/exec.h>
  15. #include <proto/dos.h>
  16.  
  17. struct StartupData
  18. {
  19.     APTR    M68kPort; /* The PPCTask can send messages here */
  20.     LONG    Status;   /* When the task exits, it can fill in the status here */
  21. };
  22.  
  23. #define    MSG_END    0x12345678
  24.  
  25. int    main(void)
  26. {
  27. struct TagItem    MyTags[10];
  28. struct Library    *PPCLibBase;
  29. void        *MyObject;
  30. ULONG        MsgID;
  31.  
  32.  
  33.   if (PPCLibBase=OpenLibrary("ppc.library",44))
  34.   {
  35.     if (MyObject=PPCLoadObject("PROGDIR:StartupPPC.elf"))
  36.     {
  37.       APTR M68kPort;
  38.  
  39.       MyTags[0].ti_Tag  = TAG_DONE;
  40.             
  41.       if (M68kPort = PPCCreatePort(MyTags))
  42.       {
  43.         APTR PPCMsg;
  44.         if (PPCMsg = PPCCreateMessage(M68kPort,sizeof(struct StartupData)))
  45.         {
  46.           struct StartupData    *StartupData;
  47.       
  48.           if (StartupData = PPCAllocVec(sizeof(struct StartupData),MEMF_ANY))
  49.           {
  50.             long    quit = FALSE;
  51.             APTR    Task;
  52.  
  53.             StartupData->M68kPort    =    M68kPort; /* Provide the PPC a way to send us messages */
  54.  
  55.             MyTags[0].ti_Tag        =    PPCTASKTAG_STARTUP_MSG;
  56.             MyTags[0].ti_Data        =(ULONG) PPCMsg;
  57.  
  58.             MyTags[1].ti_Tag        =    PPCTASKTAG_STARTUP_MSGDATA;
  59.             MyTags[1].ti_Data        =(ULONG) StartupData;
  60.  
  61.             MyTags[2].ti_Tag        =    PPCTASKTAG_STARTUP_MSGLENGTH;
  62.             MyTags[2].ti_Data        =    sizeof(struct StartupData);
  63.  
  64.             MyTags[3].ti_Tag        =    PPCTASKTAG_STARTUP_MSGID;
  65.             MyTags[3].ti_Data        =    MSG_END;
  66.  
  67.             MyTags[4].ti_Tag        =    PPCTASKTAG_MSGPORT;
  68.             MyTags[4].ti_Data        =    TRUE;
  69.  
  70.             MyTags[5].ti_Tag        =    TAG_END;
  71.  
  72.  
  73.             if (Task = PPCCreateTask(MyObject,
  74.                                      MyTags))
  75.             {
  76.               /* This check is only for own debugging purposes
  77.                * for real code this makes no sense
  78.                */
  79.               Printf("Try to locate the PPC Taskobjects\n");
  80.  
  81.               if (PPCFindTaskObject(Task))
  82.               {
  83.                 Printf("Found it\n");
  84.                 while (!quit)
  85.                 {
  86.                   APTR    thePPCMsg;
  87.  
  88.  
  89.                   PPCWaitPort(M68kPort);
  90.  
  91.                   if (thePPCMsg = PPCGetMessage(M68kPort))
  92.                   {
  93.                     MsgID    =    PPCGetMessageAttr(thePPCMsg, PPCMSGTAG_MSGID);
  94.                     switch (MsgID)
  95.                     {
  96.                       case MSG_END:
  97.                               /* Handle our reply messages here */
  98.                               /* Since the only message we send is the
  99.                                * startup msg, we quite in all cases    */
  100.                               /* Here we check the return code from the PPC task
  101.                                * We could be abit more sofisticated and display
  102.                                * appropriate message, take actions etc.
  103.                                */
  104.                               Printf("Status from PPCTask: %ld\n",StartupData->Status);
  105.                               quit    =    TRUE;
  106.                               break;
  107.  
  108.                       default:
  109.                               /* Handle our messages here */
  110.                               /* We should probably do something more interesting here */
  111.                               Printf("The message ID was: %ld\n",PPCGetMessageAttr(thePPCMsg, PPCMSGTAG_MSGID));
  112.                               PPCReplyMessage(thePPCMsg);
  113.                               break;
  114.                     }
  115.                   }
  116.                 }
  117.               }
  118.               else
  119.               {
  120.                 Printf("Error: The Taskobject wasn`t found\n");
  121.               }
  122.             }
  123.             else
  124.             {
  125.               Printf("Unable to create PPC task\n");
  126.             }
  127.             PPCFreeVec(StartupData);
  128.           }
  129.           else
  130.           {
  131.             Printf("Unable to allocate Startup Message\n");
  132.           }
  133.           PPCDeleteMessage(PPCMsg);
  134.         }
  135.         else
  136.         {
  137.           Printf("Unable to create PPC Message\n");
  138.         }
  139.         PPCDeletePort(M68kPort);
  140.       }
  141.       else
  142.       {
  143.         Printf("ERROR: Unable to allocate memory\n");
  144.       }
  145.       PPCUnLoadObject(MyObject);
  146.     }
  147.     else
  148.     {
  149.       Printf("ERROR: Couldn't load PPC Program (PPCMpeg.elf)\n");
  150.     }
  151.     CloseLibrary(PPCLibBase);
  152.   }
  153.   else
  154.   {
  155.     Printf("ERROR: Couldn't open ppc.library\n");
  156.   }
  157.   return(0);
  158. }
  159.